package com.ikaros.api;


import java.io.File;
import java.io.IOException;

import javax.annotation.Resource;

import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.ss.usermodel.*;

import com.ikaros.dao.RegionDao;


/**
 * @author: 胡国军
 * @Date 2018-01-02 19:06
 */
public class ReadExcel {
    @Resource
    private RegionDao regionDao;

    public static void main(String[] args) throws IOException,
            InvalidFormatException
    {
        File xlsFile = new File("E://广东省.xlsx");
        // 获得工作簿
        Workbook workbook = WorkbookFactory.create(xlsFile);
        // 获得工作表个数
        int sheetCount = workbook.getNumberOfSheets();
        // 遍历工作表
        for (int i = 0; i < sheetCount; i++)
        {
            Sheet sheet = workbook.getSheetAt(i);
            // 获得行数
            int rows = sheet.getLastRowNum() + 1;
            // 获得列数，先获得一行，在得到改行列数
            Row tmp = sheet.getRow(0);
            if (tmp == null)
            {
                continue;
            }
            int cols = tmp.getPhysicalNumberOfCells();
            // 读取数据
            for (int row = 0; row < rows; row++)
            {
                Row r = sheet.getRow(row);
                for (int col = 0; col < cols; col++)
                {
                    Cell cell = r.getCell(col);
                    cell.setCellType(Cell.CELL_TYPE_STRING);
                    System.out.printf("%10s", cell.getStringCellValue());
                }
                System.out.println();
            }
        }
    }

}
